package micro.beauty.common.core;

import micro.beauty.common.core.constant.SysRetCode;

/**
* @Author:         Liuliya
* @CreateDate:     2020/8/8 1:11
* @Version:        0.0.1
*/
public class ResponseUtil<T> {

    private ResponseData<T> responseData;

    public ResponseUtil() {
        responseData = new ResponseData<>();
        responseData.setCode(SysRetCode.SUCCESS.getCode());
        responseData.setMessage(SysRetCode.SUCCESS.getMessage());
    }

    public ResponseData<T> ok() {
        return this.responseData;
    }

    public ResponseData<T> data(T data) {
        this.responseData.setData(data);
        return this.responseData;
    }

    public ResponseData<T> data(T data, String msg) {
        this.responseData.setData(data);
        this.responseData.setMessage(msg);
        return this.responseData;
    }

    public ResponseData<T> error() {
        this.responseData.setCode(SysRetCode.FAILURE.getCode());
        this.responseData.setMessage(SysRetCode.FAILURE.getMessage());
        return this.responseData;
    }

    public ResponseData<T> error(String msg) {
        this.responseData.setCode(SysRetCode.FAILURE.getCode());
        this.responseData.setMessage(msg);
        return this.responseData;
    }

    public ResponseData<T> error(int code, String msg) {
        this.responseData.setCode(code);
        this.responseData.setMessage(msg);
        return this.responseData;
    }

}
